#! /bin/sh

sid=$1
instid=$2

if [ "$#" -ne 2 ]; then
    exit 1
fi

orauser=`cat /opt/howlink/lb-agent/application.properties | grep "^agent.oracle-user" | awk -F'=' '{ print $2 }' | sed 's/ //g'`
if [ -z "$orauser" ];then
    orauser=`ps -ef | grep ora_pmon | grep -v grep | head -n1 | sed -e 's/^[ \t]*//' | cut -d" " -f1`
fi

if [ -z "$orauser"];then
    orauser=oracle
fi

oraclehome=`cat /opt/howlink/lb-agent/application.properties | grep "^agent.oracle-home" | awk -F'=' '{ print $2 }' | sed 's/ //g'`
if [ -z "$oraclehome" ];then
    oraclehome=`grep -wi "$sid:"  $otab | grep "^$sid" | head -n1 | cut -f2 -d":"`
fi

lsnrctl=$oraclehome/bin/lsnrctl
service_status=`$lsnrctl status | grep -e "Service \"${sid}\""`
instance_status=`$lsnrctl status | grep -e "Instance \"${instid}\""`
if [ "$service_status" != "" -a "$instance_status" != "" ];then
    echo True
    exit 0
fi

echo False
exit 0
